"""Changed CheckMessage > Calendar to m2m

Revision ID: 27ccb45967d5
Revises: 1285335a7541
Create Date: 2023-12-04 12:38:09.463735

"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = "27ccb45967d5"
down_revision = "1285335a7541"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "calendars_check_messages",
        sa.Column("calendar_id", sa.Integer(), nullable=True),
        sa.Column("check_message_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ["calendar_id"],
            ["calendar.id"],
            name=op.f("fk_calendars_check_messages_calendar_id_calendar"),
        ),
        sa.ForeignKeyConstraint(
            ["check_message_id"],
            ["check_message.id"],
            name=op.f("fk_calendars_check_messages_check_message_id_check_message"),
        ),
    )
    op.drop_constraint(
        "fk_check_message_calendar_id_calendar", "check_message", type_="foreignkey"
    )
    op.drop_column("check_message", "calendar_id")
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "check_message",
        sa.Column("calendar_id", mysql.INTEGER(), autoincrement=False, nullable=False),
    )
    op.create_foreign_key(
        "fk_check_message_calendar_id_calendar",
        "check_message",
        "calendar",
        ["calendar_id"],
        ["id"],
    )
    op.drop_table("calendars_check_messages")
    # ### end Alembic commands ###
